package com.songcha.sakura.mvvm.comic.detail

/*
class ComicDetailDialog(val mContext: Context,val mComic: ComicListBean.ComicBean): BottomSheetDialogFragment() ,ILoadData{
    //private lateinit var mView:View
    private lateinit var viewModel:ComicDetailViewModel
    //private lateinit var mVp:ViewPager
    //private lateinit var mIvLoading:ImageView
    //private lateinit var mClDetail:ConstraintLayout
    private val mPeekHeightScale=0.7

    private lateinit var mBinding:BottomsheetComicDetailBinding


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.bottom_sheet_dialog)
        //LogUtil.log("onCreate")
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        //LogUtil.log("onCreateView")

        mBinding= BottomsheetComicDetailBinding.inflate(layoutInflater,container,false)



        //mView = LayoutInflater.from(mContext).inflate(R.layout.bottomsheet_comic_detail,container,false)

        //mVp=mView.findViewById(R.id.vp)
        //mIvLoading=mView.findViewById(R.id.iv_loading)
       // mClDetail=mView.findViewById(R.id.cl_detail)


        viewModel =
            ViewModelProvider(this).get(ComicDetailViewModel::class.java)




        viewModel.comicDetail.observe(viewLifecycleOwner){
            initData(it)
        }



       */
/* dialog?.setOnShowListener{
            onLoading()

            getData()

        }*//*



        //return mView

        return mBinding.root

    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // LogUtil.log("onViewCreated")

    }


    override fun onAttach(context: Context) {
        super.onAttach(context)
        //LogUtil.log("onAttach")
    }

    override fun onDetach() {
        super.onDetach()
        //LogUtil.log("onDetach")
    }

    override fun onStop() {
        super.onStop()
        //LogUtil.log("onStop")
    }

    override fun onDestroyView() {
        super.onDestroyView()
        //LogUtil.log("onDestroyView")
    }

    override fun onPause() {
        super.onPause()
        //LogUtil.log("onPause")
    }






    override fun onStart() {
        //LogUtil.log("onStart")
        super.onStart()




        val dialogBehavior = BottomSheetBehavior.from(mBinding.root.parent as View)
        //dialogBehavior.peekHeight=ScreenUtil.getScreenHeight(mContext)

         dialogBehavior.peekHeight =  (ScreenUtil.getScreenHeight(mContext)*mPeekHeightScale).toInt()



         dialogBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
             override fun onStateChanged(view: View, i: Int) {
                 if (i == BottomSheetBehavior.STATE_HIDDEN) {

                     dismiss()
                     dialogBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
                 }
             }

             override fun onSlide(view: View, v: Float) {}
         })

        */
/*dialog?.window?.apply {
            // 1.修改window的高度
            setLayout(-1, -1) // ViewGroup.LayoutParams.MATCH_PARENT
            // 2.修改容器的高度
            decorView.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)?.apply {
                //layoutParams.height = -1
                //layoutParams.width = -1
            }
            // 3.设置状态为展开
            dialogBehavior.state = BottomSheetBehavior.STATE_DRAGGING
        }*//*





    }



    override fun onDestroy() {
        //LogUtil.log("onDestroy")
        super.onDestroy()
    }




    override fun onResume() {
        //LogUtil.log("onResume")
        super.onResume()
    }




  */
/*  private  fun getData(){
        //mView.findViewById<>()
        viewModel.getComicDetail(mComic.href,this)

    }*//*





    private fun initData(bean: ComicDetailBean){
       // LogUtil.log("initData",isAdded)
        if(!isAdded) return

         mBinding.comic=bean

         Glide.with(mContext).load(bean.thumb).into(mBinding.ivThumb)

         mBinding.tvActors.text=bean.actors.joinToString(" ")



         val ctl=mBinding.root.findViewById<CustomTabLayout>(R.id.ctl_play_url)

         mBinding.vp.adapter= ComicPlayUrlAdapter(childFragmentManager,bean.playSource,bean.playUrlList)
         ctl.setViewPager(mBinding.vp)


    }


    override fun onActivityCreated(savedInstanceState: Bundle?) {
        //LogUtil.log("onActivityCreated")
        super.onActivityCreated(savedInstanceState)
    }


   override fun onLoading() {
        val ivLoading=mBinding.ivLoading
        Glide.with(mContext).asGif().load(R.drawable._2).into(ivLoading)

        (ivLoading.layoutParams as FrameLayout.LayoutParams).setMargins(0,
            ((ScreenUtil.getScreenHeight(requireContext())*mPeekHeightScale-100f.dp2px())/2).toInt(),0,0)
        ivLoading.visibility=View.VISIBLE
        mBinding.clDetail.visibility=View.INVISIBLE

    }

    override fun onLoadSuccess() {
        val ivLoading=mBinding.ivLoading
        ivLoading.visibility=View.GONE
        mBinding.clDetail.visibility=View.VISIBLE
    }

    override fun onLoadError() {

    }

    override fun onNoNetwork() {

    }
}*/
